001    /*
002     * Copyright 2005 Stephen McConnell
003     * Licensed  under the  Apache License,  Version 2.0  (the "License");
004     * you may not use  this file  except in  compliance with the License.
005     * You may obtain a copy of the License at
006     *
007     *   http://www.apache.org/licenses/LICENSE-2.0
008     *
009     * Unless required by applicable law or agreed to in writing, software
010     * distributed  under the  License is distributed on an "AS IS" BASIS,
011     * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
012     * implied.
013     *
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    package net.dpml.transit.registry;
019    
020    import java.io.IOException;
021    import java.net.URL;
022    import java.net.URLConnection;
023    import java.net.URLStreamHandler;
024    import java.rmi.registry.Registry;
025    
026    /** 
027     * The <code>registry</code> protocol references an remote resource
028     * published under an RMI Registry.
029     *
030     * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
031     * @version 1.0.1
032     */
033    public class Handler extends URLStreamHandler
034    {
035       /**
036        * Creation of a new registry protocol handler.
037        */
038        public Handler()
039        {
040        }
041    
042        // ------------------------------------------------------------------------
043        // implementation
044        // ------------------------------------------------------------------------
045    
046       /**
047        * Returns the default registry port.
048        * @return the registry default port
049        */
050        protected int getDefaultPort()
051        {
052            return Registry.REGISTRY_PORT;
053        }
054    
055        /**
056         * Opens a connection to the specified URL.
057         *
058         * @param url A URL to open a connection to.
059         * @return The established connection.
060         * @throws IOException If a connection failure occurs.
061         */
062        protected URLConnection openConnection( final URL url )
063            throws IOException
064        {
065            return new RegistryURLConnection( url );
066        }
067    }